'''
Created on 2011-5-19

@author: elm
'''
import ply.lex as lex
import ply.yacc as yacc

class Parser:
    """
    Base class for a lexer/parser that has the rules defined as methods
    """
    tokens = ()
    precedence = ()
    param = None

    def __init__(self):        
        lex.lex(module=self)
        yacc.yacc(module=self)
    
    def parse(self,sql):
        self.param = {}
        return yacc.parse(sql.lower())
    
    def run(self):
        while 1:
            try:
                s = raw_input('calc > ')
            except EOFError:
                break
            if not s: continue
            yacc.parse(s)